package bibliotheque;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RMIRegistry {
    
    public RMIRegistry() {
    }
    
    public static void Start(int port) {
        try {
            LocateRegistry.createRegistry(port);
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        int port = -1;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String input;
        Registry registry = null;
        do {
            if(port == -1) {
                try {
                    System.out.println("Tapez le port sur lequel lancer le rmi registry ou exit pour quitter.");
                    input = reader.readLine();
                    if(input.equals("exit")) break;
                    port = Integer.parseInt(input);
                    registry = LocateRegistry.createRegistry(port);
                } catch (NumberFormatException ex) {
                    
                } catch (RemoteException ex) {
                    port = -1;
                } catch (IOException ex) {
                    
                }
            } else {
                try {
                    System.out.println("Tapez exit pour quitter.");
                    input = reader.readLine();
                    if(input.equals("exit")) break;
                } catch (IOException ex) {
                    
                }
            }
        } while(true);
    }
}
